package com.hckjsec.system.controller;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.system.domain.WorkOaApply;
import com.hckjsec.system.service.IWorkOaApplyService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 日常申请Controller
 * 
 * @author cyt
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/work/apply")
public class WorkOaApplyController extends BaseController
{
    @Autowired
    private IWorkOaApplyService workOaApplyService;

    /**
     * 查询日常申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOaApply workOaApply)
    {
        startPage();
        List<WorkOaApply> list = workOaApplyService.selectWorkOaApplyList(workOaApply);
        return getDataTable(list);
    }

    /**
     * 导出日常申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "日常申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkOaApply workOaApply)
    {
        List<WorkOaApply> list = workOaApplyService.selectWorkOaApplyList(workOaApply);
        ExcelUtil<WorkOaApply> util = new ExcelUtil<WorkOaApply>(WorkOaApply.class);
        return util.exportExcel(list, "apply");
    }

    /**
     * 获取日常申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return AjaxResult.success(workOaApplyService.selectWorkOaApplyById(applyId));
    }

    /**
     * 新增日常申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "日常申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOaApply workOaApply)
    {
        workOaApply.setApplyName(SecurityUtils.getUserId());
        return toAjax(workOaApplyService.insertWorkOaApply(workOaApply));
    }

    /**
     * 修改日常申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "日常申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOaApply workOaApply)
    {
        return toAjax(workOaApplyService.updateWorkOaApply(workOaApply));
    }

    /**
     * 删除日常申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "日常申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(workOaApplyService.deleteWorkOaApplyByIds(applyIds));
    }
}
